package com.rc.saas.tenant.controller.member;

import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.TenantBaseController;
import com.rc.saas.tenant.base.WebPageInfo;
import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.search.member.MemberMultchargeApplySearch;
import com.rc.saas.tenant.service.member.MemberMultchargeApplyService;
import com.rc.saas.tenant.vo.member.MemberMultchargeApplyResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 一号多充审核
 * Created by sven on 2019/12/2
 */
@Controller
@RequestMapping("/member/multchargeApply")
public class MultchargeApplyController extends TenantBaseController {
    private static Logger logger = LogManager.getLogger(MultchargeApplyController.class);

    @Autowired
    private MemberMultchargeApplyService memberMultchargeApplyService;

    /**
     * 跳转到首页
     *
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String memberPage() {
        return "/templates/member/multcharge/memberMultchargeApply";
    }

    /**
     * 返回列表数据
     *
     * @return
     */
    @RequestMapping(value = "/listMemberMultchargeApply", method = RequestMethod.GET)
    @ResponseBody
    public WebPageInfo listEnterpriseMember(MemberMultchargeApplySearch search) {
        PageInfo<MemberMultchargeApplyResult> pageInfo = memberMultchargeApplyService.searchByCondition(search);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }

    /**
     * 核准
     *
     * @return
     */
    @RequestMapping(value = "/approval", method = RequestMethod.POST)
    @ResponseBody
    public TResponse approval(Long applyId, String status) {
        try {
            memberMultchargeApplyService.updateApprovalById(applyId,status);
            return TResponse.SUCCESS();
        } catch (Exception e) {
            logger.error("一号多充核准失败", e);
            return TResponse.FAIL();
        }
    }

    /**
     * 取消核准
     *
     * @return
     */
    @RequestMapping(value = "/cancelApproval", method = RequestMethod.POST)
    @ResponseBody
    public TResponse cancelApproval(Long applyId) {
        try {
            memberMultchargeApplyService.updateCancelApprovalById(applyId);
            return TResponse.SUCCESS();
        } catch (Exception e) {
            logger.error("取消核准失败", e);
            return TResponse.FAIL();
        }
    }

}
